package promote.brozen.middleware.redis;

import org.redisson.Redisson;
import org.redisson.api.RBucket;
import org.redisson.api.RBuckets;
import org.redisson.api.RedissonClient;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.concurrent.TimeUnit;

/**
 * @author Brozen
 * @date 2020/9/20 3:49 PM
 * @email brozen@qq.com
 */
public class BucketExpiryTest {

    public static void main(String[] args) {
        ApplicationContext ac = new SpringApplicationBuilder()
                .sources(RedissonConfig.class)
                .web(WebApplicationType.NONE)
                .build()
                .run(args);

        testBucket(ac);
    }


    private static void testBucket(ApplicationContext ac) {
        RedissonClient redissonClient = ac.getBean(RedissonClient.class);
        RBucket<Object> bucket = redissonClient.getBucket("test_bucket");
        bucket.set("testValue", 50, TimeUnit.SECONDS);
    }

}
